
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>高级设置示例</title>
<script type="text/javascript" src="../../jquery/1.4.4/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="jquery.aygrid.v0.0.2min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
		var mytable = $("#table1").ayGrid({ 
			dataJsonUrl	: 'aygrid.php?pro=getStu&',
			columnListDataUrl: {'department':'aygrid.php?pro=dpt'},
			columnHeader  	: ['姓名','学科','学分','通过','日期'],
			columnType	: {'stuName':'Input','department':'CombBox','creditHour':'Input','passed':'CheckBox','mydate':'Label'},
			columnWidth	: {'stuName':75,'department':85,'creditHour':30,'passed':25,'mydate':60}, 
			columnID	: ['stuName','department','creditHour','passed','mydate'],//
			gridWitdh	: 460,
			gridHeigh	: 450,
			numberOfPage	: 50,
			toolsDisplay	: true,
			pagesDisplay	: true,
			rowKey		: 'id',
			rowDelete	: function(mykey){
				
				if(mykey != undefined)alert(mykey);
				},
			gridSave		: function(data){
				var newData = [],i=0;
				jQuery.each(data,function(key,dtRow){
													 
						if(dtRow['id'] == undefined){
							newData[i] = dtRow;
							i++;
						}
													 
													 
				});
				jQuery.ajax({
					type: "POST",
					async: false,
					url: "aygrid.php?pro=add",
					data: {data:newData},
					cache: false
				});
				return true;
				},
			onCellChange	: function (me,oldv,newv){
				
				var crm = jQuery('<div />'),
				stuName = me.getValueByCid(me.rowIndex(),'stuName'),
				department = me.getValueByCid(me.rowIndex(),'department'),
				creditHour = me.getValueByCid(me.rowIndex(),'creditHour'),
				psd = me.getValueByCid(me.rowIndex(),'passed'),
				myKey = me.getRowKey(me.rowIndex());
				if(myKey != undefined )crm.load("aygrid.php?pro=psd",{id : myKey, stuName : stuName ,psd : psd,department : department,creditHour : creditHour });
			}

		});
		//bbs.test();
		$("#addrow").click(function(){
			var rowdata = {};
			rowdata['stuName'] = 'test';
			rowdata['department'] = 1;
			rowdata['creditHour'] = 5;
			rowdata['passed'] = 1;
			rowdata['mydate'] = '';
			mytable.addData(rowdata);

			});
		$("#delrows").click(function(){

			mytable.deleteRow();

			});
		$("#reload").click(function(){

			mytable.loadData('aygrid.php?pro=getStu');

			});
	}
); 	
</script>

</head>

<body><button id="addrow" type="button">添加</button><button id="delrows" type="button">删除(按住"Ctrl"键可进行多行选择删除)</button><button id="reload" type="button">重新加载数据</button>
<div id="table1"></div>
<div id="table2">提示：按"Enter"或"Tab"键可进行单元格依次切换输入。</div>
</body>
</html>
